package cn.vcjf.weapp.api.goods.service.impl;

import cn.vcjf.weapp.api.goods.entity.GoodsGroup;
import cn.vcjf.weapp.api.goods.mapper.GoodsGroupMapper;
import cn.vcjf.weapp.api.goods.service.GoodsGroupService;
import cn.vcjf.weapp.common.exception.ServiceException;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhengzihang
 * @since 2018-09-25
 */
@Service("goodsGroupService")
public class GoodsGroupServiceImpl extends ServiceImpl<GoodsGroupMapper, GoodsGroup> implements GoodsGroupService {

	@Override
	public GoodsGroup selectRepertoryForUpdate(GoodsGroup goodsGroup) {
		return baseMapper.selectRepertoryForUpdate(goodsGroup.getId());
	}
	@Override
	public GoodsGroup selectRepertoryForUpdate(int id) {
		return baseMapper.selectRepertoryForUpdate(id);
	}

	/**
	 * 增加库存
	 *
	 * @param goodsGroup
	 * @return
	 */
	@Override
	public int addGoodsGroupRepertory(GoodsGroup goodsGroup) {
		int i = baseMapper.addGoodsGroupRepertory(goodsGroup);
		if (i!=1){
			throw new ServiceException("退回库存失败!");
		}
		return i;
	}

	@Override
	public int addGoodsGroupRepertory(int id, int num) {
		GoodsGroup goodsGroup = new GoodsGroup();
		goodsGroup.setId(id);
		goodsGroup.setGoodsNum(num);
		int i = baseMapper.addGoodsGroupRepertory(goodsGroup);
		if (i!=1){
			throw new ServiceException("退回库存失败!");
		}
		return i;
	}

	/**
	 * 减少库存
	 *
	 * @param goodsGroup
	 * @return
	 */
	@Override
	public int reduceGoodsGroupRepertory(GoodsGroup goodsGroup) {
		int i = baseMapper.reduceGoodsGroupRepertory(goodsGroup);
		if (i!=1){
			throw new ServiceException("减少库存失败!");
		}
		return i;
	}

	@Override
	public int reduceGoodsGroupRepertory(int id, int num) {
		GoodsGroup goodsGroup = new GoodsGroup();
		goodsGroup.setId(id);
		goodsGroup.setGoodsNum(num);
		int i = baseMapper.reduceGoodsGroupRepertory(goodsGroup);
		if (i!=1){
			throw new ServiceException("减少库存失败!");
		}
		return i;
	}


}
